package com.ibm.jdg2e.editor.jfacetext.sqleditor;
/*
 * "The Java Developer's Guide to Eclipse"
 *   by D'Anjou, Fairbrother, Kehn, Kellerman, McCarthy
 * 
 * (C) Copyright International Business Machines Corporation, 2003, 2004. 
 * All Rights Reserved.
 * 
 * Code or samples provided herein are provided without warranty of any kind.
 */
import org.eclipse.core.filebuffers.IDocumentSetupParticipant;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentExtension3;
import org.eclipse.jface.text.IDocumentPartitioner;
import org.eclipse.jface.text.rules.FastPartitioner;

import com.ibm.jdg2e.editor.jfacetext.sqleditor.sql.SQLPartitionScanner;

/**
 * Participates in the setup of a text file buffer document.
 * <p>
 * This interface is the expected interface for extensions provided for the
 * <code>"org.eclipse.core.filebuffers.documentSetup"</code> extension point.
 * <p>
 * 
 * @see com.ibm.jdg2e.editor.jfacetext.sqleditor.sql.SQLPartitionScanner
 */
public class SQLDocumentParticipant
    implements
      IDocumentSetupParticipant {

  /**
   *  
   */
  public SQLDocumentParticipant() {
  }

  /*
   * (non-Javadoc)
   * 
   * @see org.eclipse.core.filebuffers.IDocumentSetupParticipant#setup(org.eclipse.jface.text.IDocument)
   */
  public void setup(IDocument document) {
    if (document instanceof IDocumentExtension3) {
      IDocumentExtension3 extension3 = (IDocumentExtension3) document;
      IDocumentPartitioner partitioner = new FastPartitioner(
          SQLEditorPlugin.getDefault().getSQLPartitionScanner(),
          SQLPartitionScanner.SQL_PARTITION_TYPES);
      extension3.setDocumentPartitioner(
          SQLEditorPlugin.SQL_PARTITIONING, partitioner);
      partitioner.connect(document);

    }
  }
}